<?php

namespace app\home\controller;

use think\facade\Request;

use think\Validate;;

class Register extends Base
{
    public function register()
    {
        $param = Request::param();
        // $this->ok($param);
        // die;
        //验证
        //验证规则
        $rule = [
            'username|用户名' => 'require',
            'email|邮箱' => 'require',
            'password|密码' => 'require',
            // 'code|验证码'=>'require|captcha'
        ];
        //错误信息
        $msg = [
            'username' => '用户名不能为空',
            'email' => '邮箱输入不能为空',
            'password' => '密码不能为空',
            // 'code.captcha'=>'验证码错误'
        ];

        $validate = new Validate($rule, $msg);

        if (!$validate->check($param)) {
            $this->fail($validate->getError());
        }

        // if(!/^1[3-9]\d{9}$/.test(phone)){}
        $data = [
            'username' => $param['username'],
            // 'email' => $param['phone'],
            'password' => $param['password'],
            'email' => $param['email'],
        ];
        // $this->ok($data);
        // die;
        $info = \app\home\model\Admin::insert($data);
        $this->ok();
        // if (!$res) {
        //     $this->fail('注册失败');
        // }
        // $this->ok('注册成功');
    }
}
